package PolladminFunc;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;


import utils.DBConn;

public class PolladminDAO extends DBConn{

	private ResultSet rs;
	public void add(Polladmin pa){
		try{
			super.getConnection();
			String sql="INSERT INTO PollUser(Username,Password,Email,Accessibility,FName,LName) VALUES(?,?,?,?,?,?)";
			ps=conn.prepareStatement(sql);
			ps.setString(1, pa.getUsername());
			ps.setString(2, pa.getPassword());
			ps.setString(3, pa.getEmail());
			ps.setInt(4, pa.getAccessibility());
			ps.setString(5, pa.getFname());
			ps.setString(6, pa.getLname());
			ps.executeUpdate();
		}catch(Exception e){
				e.getMessage();
				e.printStackTrace();}

	}
	
	public ArrayList<Polladmin> show(){
		ArrayList<Polladmin> pa=new ArrayList<Polladmin>();
		super.getConnection();
		String sql="SELECT Username,Email,FName,LName,CreateTime,ExpireDate FROM PollUser WHERE Accessibility=4";
		try{
			ps=conn.prepareStatement(sql);
			rs=ps.executeQuery(sql);
			Polladmin pad=null;
			while(rs.next()){
				pad=new Polladmin();
				pad.setUsername(rs.getString("username"));
				pad.setEmail(rs.getString("Email"));
				pad.setFname(rs.getString("FName"));
				pad.setLname(rs.getString("LName"));
				pad.setCreatetime(rs.getDate("CreateTime"));
				pad.setExpiredate(rs.getDate("ExpireDate"));
				pa.add(pad);
				System.out.println("execute finished");
			}
		}catch(Exception e){
			e.printStackTrace();
			e.getMessage();
		}
		return pa;

	}
	
	public void delete(Polladmin pa){
		try{
			super.getConnection();
			String delsql="DELETE FROM Polluser WHERE Username=?";
			ps=conn.prepareStatement(delsql);
			ps.setString(1, pa.getUsername());
			ps.executeUpdate();
		}catch(Exception e){
			e.getMessage();
			e.printStackTrace();
		}
	}
	
	public void update(Polladmin pa){
	}
}